//
//  BKUserHeadView.m
//  bestkeep
//
//  Created by windCould on 16/11/7.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKUserHeadView.h"
#import "BKMyCommon.h"
#import "BKUserStatusInfo.h"
#import "BKUserRequestUrl.h"
#import <SDWebImage/UIButton+WebCache.h>
@interface BKUserHeadView ()

@property (nonatomic,strong)UIImageView * bGroudImgV;
@property (nonatomic,strong)UIImageView * userLogoImgV;
@property (nonatomic,strong)UILabel * userNicKnameLab;
@property (nonatomic,strong)UIImageView * userViPLevelImgv;

@end


@implementation BKUserHeadView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       
        [self setUpViews];
    
    }

    return  self;
}

-(void)setUpViews{

    _bGroudImgV = [[UIImageView alloc]initWithFrame:CGRectZero];
    _bGroudImgV.image = [UIImage imageNamed:@"BK_My_图层-36"];
    _bGroudImgV.backgroundColor = [UIColor cyanColor];
    [self addSubview: _bGroudImgV];
    
    _userLogoImgV = [[UIImageView alloc]init];
    _userLogoImgV.image = [UIImage imageNamed:@"BK_My_default_head"];
    _userLogoImgV.layer.cornerRadius = 37.5f;
    _userLogoImgV.layer.masksToBounds = YES;
//    [_userLogoImgV setContentScaleFactor:3];
//    _userLogoImgV.layer.borderWidth = 1;
//    _userLogoImgV.layer.borderColor = [UIColor whiteColor].CGColor;
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userLogoBtnClick)];
    [_userLogoImgV setUserInteractionEnabled:YES];
    [_userLogoImgV addGestureRecognizer:tap];
    [self addSubview:_userLogoImgV];

    _userNicKnameLab = [[UILabel alloc]initWithFrame:CGRectZero];
    _userNicKnameLab.font = [UIFont boldSystemFontOfSize:18];
    _userNicKnameLab.textColor = [UIColor whiteColor];
    _userNicKnameLab.textAlignment = NSTextAlignmentCenter;
    _userNicKnameLab.text = @"登录／注册";
    [self addSubview:_userNicKnameLab];
    
    _userViPLevelImgv = [[UIImageView alloc]initWithFrame:CGRectZero];
    _userViPLevelImgv.hidden = NO;
    [self addSubview:_userViPLevelImgv];
    
    [self layoutViews];
    
}

-(void)layoutViews{

    [_bGroudImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top);
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.bottom.mas_equalTo(self.mas_bottom);
    }];
    
    
    [_userLogoImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(@(75));
        make.width.mas_equalTo(@(75));
        make.centerX.mas_equalTo(_bGroudImgV.mas_centerX);
        make.top.mas_equalTo(_bGroudImgV.mas_top).offset(53);
    }];
    
    
    [_userNicKnameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(_bGroudImgV.mas_centerX);
        make.top.mas_equalTo(_userLogoImgV.mas_bottom).offset(3);
        make.height.mas_equalTo(@(25));
    }];
    
    [_userViPLevelImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(_bGroudImgV.mas_centerX).offset(0);
        make.top.mas_equalTo(_userNicKnameLab.mas_bottom).offset(2);
        make.height.mas_equalTo(@(13));
        make.width.mas_equalTo(@(46));
    }];
}

-(void)setUserLogoUrlStr:(NSString *)userLogoUrlStr
{
    _userLogoUrlStr = userLogoUrlStr;
    
    if (![_userLogoUrlStr isEqualToString:@""]||_userLogoUrlStr!= nil) {
        
         [_userLogoImgV load:_userLogoUrlStr placeholderImage:[UIImage imageNamed: @"BK_My_default_head"]];
        
    } else {
    
        [_userLogoImgV setImage:[UIImage imageNamed: @"BK_My_default_head"]];
    }
}

-(void)setUserNickName:(NSString *)userNickName
{
    _userNicKnameLab.text = userNickName;

}

-(void)setUserLevel:(NSString *)userLevel
{
    _userLevel = userLevel;
    if ([_userLevel isEqualToString:@"-1"]) {
        
        _userViPLevelImgv.image = [UIImage imageNamed:@"BK_My_普通会员"];
    }
    else{
        
        _userViPLevelImgv.image = [UIImage imageNamed:[NSString stringWithFormat:@"BK_My_Vip%@",_userLevel]];
    }
    
}


/*点击用户图像，进行相应操作
 *用户未登陆时，点击图像进行登陆
 *用户已登陆时，点击用户图像进入用户信息的设置
 */
-(void)userLogoBtnClick
{
    if ([self.headerViewDelegate respondsToSelector:@selector(bKUserHeaderView:clickLogoBtn:)]) {
        
        [self.headerViewDelegate bKUserHeaderView:self clickLogoBtn:nil];
    }
    

}

@end
